package com.atguigu.democustomer.service.impl;

import com.atguigu.democustomer.bean.Customer;
import com.atguigu.democustomer.mapper.CustomerMapper;
import com.atguigu.democustomer.service.CustomerService;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@DS("mysql0926")
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper,Customer> implements CustomerService {

    @Autowired
    CustomerMapper customerMapper;


    @Override
    public String getCustomerById(String id) {

        System.out.println("2.Service");

//        Customer customer = customerMapper.getCustomerById(id);
        //TODO Mybatis-plus给mapper赋予功能去sql，通过方法来完成操作
//        Customer customer = customerMapper.selectById(id);

        QueryWrapper<Customer> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", id);
        Customer customer = customerMapper.selectOne(queryWrapper);
        return customer.toString();
    }

    @DS("mysql0828")
    @Override
    public void saveCustomerService(Customer customer) {
        customerMapper.insert(customer);
    }


}
